﻿using SD.Infrastructure.EntityBase;
using System.Text;

namespace SD.ContentSystem.Domain.Entities
{
    /// <summary>
    /// 相片
    /// </summary>
    public class Photo : AggregateRootEntity, ISortable
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected Photo() { }
        #endregion

        #region 01.创建相片构造器

        /// <summary>
        /// 创建相片构造器
        /// </summary>
        /// <param name="photoAlbumNo">相册编号</param>
        /// <param name="photoName">相片名称</param>
        /// <param name="sort">排序</param>
        /// <param name="url">链接地址</param>
        /// <param name="imagePath">图片路径</param>
        /// <param name="thumbPath">缩略图路径</param>
        /// <param name="description">描述</param>
        public Photo(string photoAlbumNo, string photoName, string imagePath, string thumbPath, string url, int sort, string description)
            : this()
        {
            this.PhotoAlbumNo = photoAlbumNo;
            this.Name = photoName;
            this.ImagePath = imagePath;
            this.ThumbPath = thumbPath;
            this.Url = url;
            this.Sort = sort;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #endregion

        #region # 属性

        #region 相册编号 —— string PhotoAlbumNo
        /// <summary>
        /// 相册编号
        /// </summary>
        public string PhotoAlbumNo { get; private set; }
        #endregion

        #region 相片名称 —— string Name
        /// <summary>
        /// 相片名称
        /// </summary>
        public string Name { get; private set; }
        #endregion

        #region 图片地址 —— string ImagePath
        /// <summary>
        /// 图片地址
        /// </summary>
        public string ImagePath { get; private set; }
        #endregion

        #region 缩略图地址 —— string ThumbPath
        /// <summary>
        /// 缩略图地址
        /// </summary>
        public string ThumbPath { get; private set; }
        #endregion

        #region 链接地址 —— string Url
        /// <summary>
        /// 链接地址
        /// </summary>
        public string Url { get; private set; }
        #endregion

        #region 相片排序 —— int Sort
        /// <summary>
        /// 相片排序
        /// </summary>
        public int Sort { get; private set; }
        #endregion

        #region 描述 —— string Description
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; private set; }
        #endregion

        #region 导航属性 - 相册 —— PhotoAlbum PhotoAlbum
        /// <summary>
        /// 导航属性 - 相册
        /// </summary>
        public virtual PhotoAlbum PhotoAlbum { get; internal set; }
        #endregion

        #endregion

        #region # 方法

        #region 修改相片信息 —— void UpdateInfo(string photoName, string url...
        /// <summary>
        /// 修改相片信息
        /// </summary>
        /// <param name="photoName">相片名称</param>
        /// <param name="sort">排序</param>
        /// <param name="url">链接地址</param>
        /// <param name="description">描述</param>
        public void UpdateInfo(string photoName, string url, int sort, string description)
        {
            this.Name = photoName;
            this.Url = url;
            this.Sort = sort;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #region 初始化关键字 —— void InitKeywords()
        /// <summary>
        /// 初始化关键字
        /// </summary>
        private void InitKeywords()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(this.Name);
            builder.Append(this.Description);

            base.SetKeywords(builder.ToString());
        }
        #endregion

        #endregion
    }
}
